﻿#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <set>

QT_BEGIN_NAMESPACE
namespace Ui
{
    class MainWindow;
}
QT_END_NAMESPACE
class MainWindowPrivate;
class QTreeView;
class QCustomPlot;
class ElementTreeModel;
class ElementsReader;
class QListWidget;
class ElementTreeItem;
class QPlainTextEdit;
class DialogSetCurve;
class QListWidgetItem;
class ListWidgetItem;
class TreeFilterProxyModel;
class QTableWidget;
class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    MainWindow(QWidget *parent = nullptr);
    ~MainWindow();
    void openFiles(const QStringList &fileNames);
    void openFile(const QString &fileName);
private slots:
    void onActionOpenFileTriggered();

    void onTreeViewDoubleClicked(const QModelIndex &index);

    void onListWidgetSelectDatasDoubleClicked(const QModelIndex &index);

    void onListWidgetSelectDatasItemChanged(QListWidgetItem *item);

    void onListWidgetSelectDatasCustomContextMenuRequested(const QPoint &pos);

    void on_actionClear_triggered();

    void on_lineEdit_textChanged(const QString &arg1);

    void on_treeView_customContextMenuRequested(const QPoint &pos);

    void on_actionExport_triggered();

    void on_actionExportPicture_triggered();

    void on_actionOriginal_triggered();

    void on_actionMeasurement_toggled(bool checked);

    void updateMeasurementTable();

private:
    void initForm();
    void bind();
    void removeListWidgetItem(ListWidgetItem *item);
    void removeListWidgetItem(int index);
    int getMeasurementTableColCount();
    // 添加一个测值
    void addValueOfMeasurement(ListWidgetItem *item);
    void updateMeasurement(int row);
    // 更新测值表格
    void updateMeasurementTableColumn();

    // 调整绘图轴,不会重绘，需要自己调用
    void adjustPlotAxis();

private:
    Ui::MainWindow *ui;
    DialogSetCurve *mDialogSetCurve = nullptr;
    MainWindowPrivate *mPrivate;
    ElementTreeModel *mTreeModel;
    ElementsReader *mTreeModeReader;
    TreeFilterProxyModel *mpFilterProxyModel;
    QListWidget *mListWidgetSelectDatas;
    QPlainTextEdit *mTextEditMessage;
    QTableWidget *mTableWidgetMeasurement;
    std::set<ElementTreeItem *> mSetSelectDatas;
    std::set<QString> mOpenFiles;
    unsigned int mSelectedCount = 0;
    double mYMaxData = std::numeric_limits<double>::min();
    double mYMinData = std::numeric_limits<double>::max();
    double mXMaxData = std::numeric_limits<double>::min();
    double mXMinData = std::numeric_limits<double>::max();
    friend class MainWindowPrivate;
};
#endif // MAINWINDOW_H
